package com.mm.cme.kotlin_001.level01.i_001_type_convert

import com.mm.cme.kotlin_001.utils.pl

/**
 * Descriptions：类型转换
 * <p>
 * Author：ChenME
 * Date：2017/7/16
 * Email：ibelieve1210@163.com
 */
fun main(args: Array<String>) {
    val parent: Parent = Child()
    if (parent is Child) {
        pl(parent.name)
    }

    val string_a: String? = "hello"

//    pl(string_a!!.length)

    if (null != string_a) {
        pl(string_a.length)
    }

    val parent_a: Parent = Parent()
//    val child_a: Child? = parent_a as Child // 和java一样，转化失败，会抛出异常
    val child_a: Child? = parent_a as? Child // 这种情况下，转化失败会返回一个null，不会抛出异常
}